<template>
  <div>
    <el-form ref="form" :model="form" :rules="rules" :disabled="isDisabled"  label-width="80px">
      <el-form-item label="名称" prop="pocessName">
        <el-input v-model="form.pocessName" placeholder="请输入名称" />
      </el-form-item>
      <el-form-item label="邮件模板">
        <Editor v-model="form.mailTemplate" :min-height="192"/>
      </el-form-item>
      <el-form-item label="工作流id" prop="definitionId">
        <el-input v-model="form.definitionId" placeholder="请输入工作流id" />
      </el-form-item>
      <el-form-item label="状态">
        <el-radio-group v-model="form.status">
          <el-radio
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictValue"
          >{{dict.dictLabel}}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="删除标志" prop="delFlag">
        <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
      </el-form-item>
    </el-form>
    <div slot="footer" v-if="!isDisabled" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </div>

</template>

<script>
import { listPocess, getPocess, delPocess, addPocess, updatePocess, exportPocess } from "@/api/activiti/pocess";
import Editor from '@/components/Editor';
export default {
components: { Editor },
  props: {
    id: {
      type: [String,Number],
    },
    open: {
      type: [Boolean],
    },
    isDisabled:{
       type: Boolean,
       default: false,
    }
  },

  data() {
    return{
         form :{},

         // 状态字典
         statusOptions: [],
         // 表单校验
         rules: {
         },
    };
  },
  created(){
     this.initDate();
     this.initDicts();
  },
  watch: {
    /* 监听打开状态 */
      open: function (newOpen, oldOpen) {
        //显示则刷新
        if(newOpen){
          console.log("监听打开状态",this.id)
          this.initDate();
        }
      },
  },
  methods: {
    /* 初始化form */
    initDate(){
         if(this.id){
           getPocess(this.id).then(response => {
                   this.form = response.data;
           });
         }else{
           //新增页面清空
           this.form={};
         }
    },
    /* 加载码表 */
    initDicts(){
      this.getDicts("sys_user_sex").then(response => {
        this.statusOptions = response.data;
      });
    },



     /** 提交按钮 */
     submitForm() {
       this.$refs["form"].validate(valid => {
         if (valid) {
           if (this.form.pocessId != null) {
             updatePocess(this.form).then(response => {
               this.msgSuccess("修改成功");
                this.parentRefresh();
              // this.getList();
             });
           } else {
             addPocess(this.form).then(response => {
               this.msgSuccess("新增成功");
               this.parentRefresh();
              //  this.getList();
             });
           }
         }
       });
     },
      /* 关闭子页面*/
     cancel() {
      this.$emit("update:open", !this.open);
     },

     /* 关闭子页面刷新父页面 */
     parentRefresh(){
        this.$emit("update:open", !this.open);
        this.$emit("doRefresh");
     },
  },

}
</script>

<style>
</style>
